package hrx.dao;


import hrx.entity.Task;
import hrx.entity.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.List;

@Repository
public interface TaskDao extends JpaRepository<Task, Integer> , JpaSpecificationExecutor<Task> {

    List<Task> findByIdIn(List<Integer> taskIds);


    @Query(value = "SELECT * FROM student_tasks \n" +
            "WHERE (COALESCE(:school, '') = '' OR school = :school)\n" +
            "  AND (:status IS NULL OR status = :status)\n" +
            "  AND (:priceMin IS NULL OR reward >= :priceMin)\n" +
            "  AND (:priceMax IS NULL OR reward <= :priceMax)\n" +
            "  AND (COALESCE(:words, '') = '' OR task_name LIKE CONCAT('%', :words, '%'))",
            nativeQuery = true)

    List<Task> myFind(@Param("school") String school,
                      @Param("status") Integer status,
                      @Param("priceMin") BigDecimal priceMin,
                      @Param("priceMax") BigDecimal priceMax,
                      @Param("words") String words);

    @Query(value = "SELECT * FROM `student_tasks`\n" +
                    "WHERE school = ?1 AND\n" +
                    "`status` = ?2 AND\n" +
                    "reward BETWEEN ?3 AND ?4 AND\n" +
                    "task_name LIKE CONCAT('%', ?5, '%')"
                ,nativeQuery = true)
    List<Task> findByTask(String school, Integer status, BigDecimal priceMin, BigDecimal priceMax, String taskName);
}
